﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;

namespace MINERP.DAL.InfoConfig
{
    public  class PaperFaceDAL:DALBase
    {
        private static ObjectQuery<paperFace> GetPaperFaces()
        {
            return DataEntites.paperFace;
        }


        /// <summary>
        /// Get paperFace list
        /// </summary>
        /// <returns></returns>
        public static List<paperFace> GetPaperFaceList()
        {
            List<paperFace> list = new List<paperFace>();
            foreach (paperFace paperFace in GetPaperFaces())
            {
                list.Add(paperFace);
            }
            return list;
        }

        /// <summary>
        ///  Get paperFace object
        /// </summary>
        /// <param name="paperFaceName"></param>
        /// <returns></returns>
        public static paperFace GetPaperFaceObj(string paperFaceName)
        {
            return DataEntites.paperFace.First(p => p.Name == paperFaceName);
        }

        /// <summary>
        ///  Get paperFace object
        /// </summary>
        /// <param name="paperFaceName"></param>
        /// <returns></returns>
        public static paperFace GetPaperFaceObj(int id)
        {
            return DataEntites.paperFace.First(p => p.PaperFaceID == id);
        }

        /// <summary>
        /// 添加纸面
        /// </summary>
        /// <param name="obj"></param>
        public static void  Add(paperFace obj)
        {
            DataEntites.AddTopaperFace(obj);
            DataEntites.SaveChanges();
        }
        /// <summary>
        /// 更新纸面
        /// </summary>
        /// <param name="obj"></param>
        public static void Update(paperFace obj)
        {
            paperFace paperFaceObj = GetPaperFaceObj(obj.PaperFaceID);
            paperFaceObj.Name = obj.Name;
            paperFaceObj.remark = obj.remark;
            DataEntites.SaveChanges();
        }
        /// <summary>
        /// 启用
        /// </summary>
        /// <param name="obj"></param>
        public static void Useable(paperFace obj)
        {
            paperFace paperFaceObj = GetPaperFaceObj(obj.PaperFaceID);
            paperFaceObj.Status = 1;
            DataEntites.SaveChanges();
        }
        /// <summary>
        /// 停用
        /// </summary>
        /// <param name="obj"></param>
        public static void Disable(paperFace obj)
        {
            paperFace paperFaceObj = GetPaperFaceObj(obj.PaperFaceID);
            paperFaceObj.Status = 2;
            DataEntites.SaveChanges();
        }
        /// <summary>
        /// 删除纸面
        /// </summary>
        /// <param name="obj"></param>
        public static void Delete(paperFace obj)
        {
            paperFace paperFaceObj = GetPaperFaceObj(obj.PaperFaceID);
            paperFaceObj.Status = 3;
            DataEntites.SaveChanges();
        }

    }
}